//
// Created by Administrator on 2023/11/23.
//
#include "bits/stdc++.h"
using namespace std;
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     string val；
 *     TreeNode *left;
 *     TreeNode *right;
 * };
 */
struct TreeNode {
    string val;
    TreeNode *left;
    TreeNode *right;
};
class Solution {
public:
    string ans;
    void dfs(TreeNode *root){
        if(!root)
            return;
        if(!root->left && !root->right)
            ans += root->val;
        else
        {
            ans += '(';
            dfs(root->left);
            ans += root->val;
            dfs(root->right);
            ans += ')';
        }
    }

    string expressionTree(TreeNode* root) {
        dfs(root->left), ans += root->val, dfs(root->right);
        return ans;
    }

};
